/**
 * 客户列表
 */

var play_record = new Object({
    table: null,
    init: function () {
        if (null != this.table)
            return;
        this.queryInfo();
    },
    queryInfo: function () {
        this.table = $('#tb_play_record').bootstrapTable({
            url: contextPath + '/play/record/listData.json',
            responseHandler: function (res) {
                return res.data;
            },
            queryParams: function (params) {
                return params;
            },
            pagination: true,
            pageList: '[10,20, 50, 100]',
            //showColumns: true,
            showRefresh: true,
            showToggle: true,
            //showPaginationSwitch:true,
            sidePagination: 'server',
            //striped:true,
            sortable: false,
            height: 700,
            search: true,
            searchAlign: 'left',
            /*  toolbar: '<div style="float: left;margin-right:5px;">' +
             '    <button class="btn btn-default" type="button" onclick="agent_mg.add()">' +
             '        <i style="margin-right:2px;" class="fa fa-search"></i>' +
             '        <span>新增</span>' +
             '    </button>' +
             '</div>',*/
            idField: 'id',
            uniqueId: 'id',
            //singleSelect: true,
            clickToSelect: true,
            columns: [{
                field: 'playTime',
                title: '游戏时间',
                align: 'center',
                width: 100,
                formatter: function (value, row, index) {
                    return (new Date(value)).Format("yyyy-MM-dd hh:mm")
                }
            }, {
                field: 'player.nickname',
                title: '昵称',
                width: 100
            }, {
                field: 'waWa.name',
                title: '娃娃名称',
                width: 100
            }, {
                field: 'waWaType.typeName',
                title: '娃娃类型',
                width: 100
            }, {
                field: 'payItemNum',
                title: '游戏币数',
                width: 60
            }, {
                field: 'playResult',
                title: '游戏结果',
                width: 60,
                formatter: function (value, row, index) {
                    if (value == 1) {
                        return '成功'
                    } else {
                        return '失败'
                    }
                }
            }, {
                field: 'videoStatus',
                title: '视频状态',
                width: 60,
                formatter: function (value, row, index) {

                    if (value == 0) {
                        return '无'
                    } else if (value == 1) {
                        return '生成中'
                    } else if (value == 2) {
                        return '<a href="javascript:void(0);" onclick="play_record.playVideo(\'' + row.videoUrl + '\')">可用</a>'
                    } else {
                        return "-";
                    }

                }
            }, {
                field: 'isDeliver',
                title: '是否发货',
                width: 60,
                formatter: function (value, row, index) {
                    if (row.playResult == 1) {
                        if (value == 0) {
                            return '待申请'
                        } else if (value == 1) {
                            return '待发货'
                        } else if (value == 2) {
                            return '已发货'
                        } else if (value == 3) {
                            return '已收货'
                        } else if (value == 4) {
                            return '已拒绝'
                        } else {
                            return '未知'
                        }
                    } else {
                        return '-'
                    }
                }
            }, {
                field: 'waWaMachine.code',
                title: '娃娃机编号',
                width: 60
            }, {
                field: 'op',
                title: '操作',
                align: 'center',
                width: 100,
                formatter: function (value, row, index) {
                    var strHtml = '';
                    //strHtml += '<a href="javascript:void(0);" onclick="client_list.edit('+row.id+',\''+row.name+'\','+row.ratio+')">编辑</a>&nbsp;&nbsp;';
                    strHtml = '<div class="btn-group">' +
                        '<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">更多<i class="fa fa-caret-down"></i></button>' +
                        '   <ul class="dropdown-menu">' +
                        '       <li><a href="javascript:void(0);" onclick="play_record.getVideoUrl(\'' + row.videoUrl + '\')">视频地址</a></li>' +
                        '   </ul>' +
                        '</div>'
                    return strHtml;
                }
            }]
        });
        $('.search input').attr("placeholder", "微信昵称");
    },
    getVideoUrl: function (videoUrl) {
        var videoUrlModal = '<div id="videoUrlModal" class="modal fade" tabindex="-1" role="dialog" style="display: none;">' +
            '   <div class="modal-dialog">' +
            '       <div class="modal-content">' +
            '           <div class="modal-header">' +
            '<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>' +
            '               <h4 class="modal-title" id="setWxInfoModalLabel">视频地址</h4>' +
            '           </div>' +
            '           <div class="modal-body">' +
            '               ' + videoUrl +
            '           </div>' +
            '</div>' +
            '   </div>' +
            '</div>';
        /**
         * 添加html中，隐藏
         */
        document.body.appendChild($(videoUrlModal)[0]);
        $('#videoUrlModal').on('hidden.bs.modal', function () {
            document.body.removeChild($('#videoUrlModal')[0]);
        });

        //显示
        $("#videoUrlModal").modal('show')
    },
    playVideo: function (videoUrl) {
        var videoModal = '' +
            '<div id="videoModal" class="modal fade" tabindex="-1" role="dialog" style="display: none;">' +
            '   <div class="modal-dialog">' +
            '       <div class="modal-content">' +
            '           <div class="modal-header">' +
            '               <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>' +
            '               <h4 class="modal-title" id="setWxInfoModalLabel">视频</h4>' +
            '           </div>' +
            '           <div class="modal-body" style="text-align: center;">' +
            '              <video height="600px" width="400px" src="'+videoUrl+'" controls="controls"></video>' +
            '           </div>' +
            '           <div class="modal-footer">' +
            '               <center>' +
            '                   <button class="btn btn-primary" type="button" data-dismiss="modal" aria-hidden="true">关闭</button>' +
            '               </center>' +
            '           </div>' +
            '       </div>' +
            '   </div>' +
            '</div>';
        /**
         * 添加html中，隐藏
         */
        document.body.appendChild($(videoModal)[0]);
        $('#videoModal').on('hidden.bs.modal', function () {
            document.body.removeChild($('#videoModal')[0]);
        });

        //显示
        $("#videoModal").modal('show')
    }
});